package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_559 {

    public int maxDepth(Node root) {
        if (root == null) {
            return 0;
        } else if (root.children==null) {
            return 1;
        }
        int nodeMax = 0;
        for (Node child : root.children) {
            nodeMax = Math.max(nodeMax, maxDepth(child));
        }
        return nodeMax + 1;
    }

    public static void main(String[] args) {
        Solution_559 model = new Solution_559();
        Node node = new Node(1);

        Node node1 = new Node(3);
        Node node2 = new Node(2);
        Node node3 = new Node(4);
        List<Node> list = new ArrayList<>();
        list.add(node1);
        list.add(node2);
        list.add(node3);
        node.children = list;

        Node node4 = new Node(5);
        Node node5 = new Node(6);

        List<Node> list1 = new ArrayList<>();
        list1.add(node4);
        list1.add(node5);
        node1.children = list1;

        System.out.println(model.maxDepth(node));
    }

    static class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    };
}
